package com.itheima.mapper;

import com.itheima.pojo.Pet;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PetMapper {
    //新增
    @Insert("insert into pet(img,name,species,sex,age,type,status,descr,create_user,weight) " +
            "values(#{img},#{name},#{species},#{sex},#{age},#{type},#{status},#{descr},#{createUser},#{weight})")
    void add(Pet pet);


    //根据用户名查询所有
    @Select("select * from pet where create_user =  #{userName}")
    List<Pet> list(String userName);

    //用于后台管理员显示各用户的宠物信息
//    @Select("select * from pet")
//    List<Pet> all();

    List<Pet> all(String createUser);

    //根据id查询
    @Select("select * from pet where id = #{id}")
    Pet findById(Integer id);

    //更新
    @Update("update pet set img=#{img},species=#{species},name=#{name},sex=#{sex},age=#{age},type=#{type},status=#{status},descr=#{descr} where id=#{id}")
    void update(Pet pet);


    //删除
    @Delete("delete from pet where id = #{id}")
    void delete(Pet pet);
}
